package persistence;

import persistence.util.TestConnectionProvider;
/**
 * @author paul jaklitsch
 * 
 * Test-Implementation of DAOFactory-Interface
 * it needs to replace the default connection providers, set in all DAO impls super class
 * JdbcDAOBase, with a test connection provider
 * @see DAOFactory
 *
 */
public class DAOFactoryJdbcTestImpl extends DAOFactoryJdbcImplBase implements DAOFactory{
	
	public DAOFactoryJdbcTestImpl() {
		this("daotest.properties");
	}
	
	public DAOFactoryJdbcTestImpl(String connectionPropertiesFile) {
		super (connectionPropertiesFile, new TestConnectionProvider());
	}

	@Override
	public SubscriptionDAO getSubscriptionDAO() {
		SubscriptionDAOJdbcImpl subscriptionDAO = new SubscriptionDAOJdbcImpl();
				
		subscriptionDAO.setLibraryLocationDAO(getLibraryLocationDAO());
		
		BindingDetailsDAOJdbcImpl bindingDetailsDAO = new BindingDetailsDAOJdbcImpl();
		subscriptionDAO.setBindingDetailsDAO(bindingDetailsDAO);
		

		subscriptionDAO.setCostUnitDAO(getCostUnitDAO());
		
		subscriptionDAO.setPeriodicalDAO(getPeriodicalDAO());		
		
		subscriptionDAO.setPurchaserDAO(getPurchaserDAO());
		
		subscriptionDAO.setSupplierDAO(getSupplierDAO());
		
		subscriptionDAO.setPredefinedEntryDAO(getPredefinedEntryDAO());
		
		return subscriptionDAO;
	}
	
	public SupplierDAO getSupplierDAO() {
		SupplierDAOJdbcImpl supplierDAO = new SupplierDAOJdbcImpl();
		supplierDAO.setCityDAO(getCityDAO());
		return supplierDAO;
	}
	
	public PredefinedEntryDAO getPredefinedEntryDAO() {
		PredefinedEntryDAOJdbcImpl predefEntryDAO = new PredefinedEntryDAOJdbcImpl();
		predefEntryDAO.setPredefinedParamDAO(getPredefinedParamDAO());		
		return predefEntryDAO;
	}

	public PredefinedParamDAO getPredefinedParamDAO() {
		PredefinedParamDAOJdbcImpl predefParamDAO = new PredefinedParamDAOJdbcImpl();
		return predefParamDAO;
	}

	@Override
	public PeriodicalDAO getPeriodicalDAO() {
		PeriodicalDAOJdbcImpl periodicalDAO = new PeriodicalDAOJdbcImpl();
		periodicalDAO.setPredefinedEntryDAO(getPredefinedEntryDAO());		
		return periodicalDAO;
	}
	
	public CityDAO getCityDAO() {
		CityDAOJdbcImpl cityDAO = new CityDAOJdbcImpl();
		return cityDAO;
	}
	
	public LibraryLocationDAO getLibraryLocationDAO() {
		LibraryLocationDAOJdbcImpl libraryLocationDAO = new LibraryLocationDAOJdbcImpl();
		libraryLocationDAO.setCityDAO(getCityDAO());
		return libraryLocationDAO;
	}

	@Override
	public CostUnitDAO getCostUnitDAO() {
		CostUnitDAOJdbcImpl costUnitDAO = new CostUnitDAOJdbcImpl();
		costUnitDAO.setLibraryLocationDAO(getLibraryLocationDAO());
		return costUnitDAO;
	}

	@Override
	public PurchaserDAO getPurchaserDAO() {
		PurchaserDAOJdbcImpl purchaserDAO = new PurchaserDAOJdbcImpl();
		purchaserDAO.setLibraryLocationDAO(getLibraryLocationDAO());
		return purchaserDAO;
	}

	@Override
	public UserDAO getUserDAO() {
		UserDAOJdbcImpl userDAO = new UserDAOJdbcImpl();
		userDAO.setLibraryLocationDAO(getLibraryLocationDAO());
		userDAO.setRoleDAO(getRoleDAO());
		return userDAO;
	}

	@Override
	public RoleDAO getRoleDAO() {
		RoleDAOJdbcImpl roleDAO = new RoleDAOJdbcImpl();
		return roleDAO;
	}
}